# 算工时
import pandas as pd

import workdays

df=pd.DataFrame({
    "项目":['a','b','c'],
    "开始日期":['2020-04-25','2020-07-10','2021-01-15'],
    "结束日期":['2020-05-22','2020-08-10','2021-01-30']
})

print(df)

dates=pd.date_range("2019-01-01",'2021-12-20')

df_work=pd.DataFrame(dates,index=dates,columns=['day']).agg({
    'day':lambda d:workdays.is_work(d) }).loc[lambda x:x.day]

print(df_work)

long=lambda s,e:df_work.loc[s:e].day.count()
long2=lambda s,e:[long(s,e) for s,e in zip(s,e)]

df=df.astype({'开始日期':'datetime64[ns]','结束日期':'datetime64[ns]'}).assign(
    工时=long2(df['开始日期'],df['结束日期']))
print(df)